package cn.yotta.user.core.web.controller.common;

import cn.yotta.user.api.params.captcha.CaptchaCheckRequest;
import cn.yotta.user.api.vo.CaptchaVo;
import cn.yotta.user.core.server.service.common.CaptchaService;
import cn.yotta.user.core.web.utils.ApiExecutor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author wyaoyao
 * @date 2022/11/9 9:59
 */
@RestController
@RequestMapping("user/common/captcha")
@Slf4j
@Api(tags = "图片验证码")
public class CaptchaController {

    private final CaptchaService captchaService;

    public CaptchaController(CaptchaService captchaService) {
        this.captchaService = captchaService;
    }

    @ApiOperation("获取图片验证码-公共接口")
    @GetMapping
    public CaptchaVo getCaptcha() {
        return ApiExecutor.execute(captchaService::genCaptcha);
    }

    @ApiOperation("校验图片验证码-公共接口")
    @PostMapping
    public Boolean checkCaptcha(@RequestBody CaptchaCheckRequest request) {
        return ApiExecutor.execute(captchaService::checkCaptcha, request);
    }
}
